package texts;

import moment.Utiles;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class MessagePage extends Utiles {
    // 由于站内信没有页面， 这里就直接进入文章列表页，然后在进行测试
    public static String url = "http://110.41.84.205:9091/index.html";
    public MessagePage() {
        super(url);
    }
    // 打开站内信
    public void messagePageRight() {
        // 校验是否打开成功
        driver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1)"));
        driver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a")).click();
        String text = driver.findElement(By.cssSelector("#btn_details_send_message")).getText();
        assert "发私信".equals(text);
    }

    /**
     * 发送成功
     * 1. 发送内容为空
     * 2. 发送给自己
     */
    public void messagePageSec() throws InterruptedException {
        // 校验页面是否正确
        String text = driver.findElement(By.cssSelector("#btn_details_send_message")).getText();
        assert "发私信".equals(text);
        driver.findElement(By.cssSelector("#btn_details_send_message")).click();

        // 发送空内容
//        String text1 = driver.findElement(By.cssSelector("#index_message_modal > div > div > div.modal-header > h5")).getText();
//        String text2 = driver.findElement(By.cssSelector("#btn_index_send_message")).getText();
        Thread.sleep(500);
        driver.findElement(By.cssSelector("#index_message_receive_content")).sendKeys("发送测试");
        driver.findElement(By.cssSelector("#btn_index_send_message")).click();
        driver.findElement(By.cssSelector("#index_message_receive_cancel")).click();
    }

    /**
     * 给自己发送站内信
     */
    public void messagePageFail() {
        // 刷新
        driver.navigate().refresh();
        // 跳转用户个人中心
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown > a")).click();
        driver.findElement(By.cssSelector("#index_user_profile")).click();
        // 测试给自己发送站内信
        driver.findElement(By.cssSelector("#btn_profile_send_message")).click();
        driver.findElement(By.cssSelector("#index_message_receive_content")).sendKeys("站内信测试");
        driver.findElement(By.cssSelector("#btn_index_send_message")).click();

    }
}
